<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> UDT Reference</title>
<link rel="stylesheet" href="udtdoc.css" type="text/css" />
</head>

<body>
<div class="ref_head">&nbsp;UDT Reference: Functions</div>

<h4 class="func_name"><strong>sendfile</strong></h4>
<p>The <b>sendfile</b> method sends out part or the whole of a local file.</p>

<div class="code">int64_t sendfile(<br />
&nbsp; UDTSOCKET <font color="#FFFFFF">u</font>,<br />
&nbsp; fstream& <font color="#FFFFFF">ifs</font>,<br />
&nbsp; const int64_t&amp; <font color="#FFFFFF">offset</font>,<br />
&nbsp; const int64_t <font color="#FFFFFF">size</font>,<br />
&nbsp; const int <font color="#FFFFFF">block</font> = 7320000<br />
);</div>

<h5>Parameters</h5>
<dl>
  <dt><i>u</i></dt>
  <dd>[in] Descriptor identifying a connected socket.</dd>
  <dt><i>ifs</i></dt>
  <dd>[in] C++ fstream descriptor for the file to read data from.</dd>
  <dt><i>offset</i></dt>
  <dd>[in, out] The offset position from where the data is read from the file. After the call returns, this value holds the updated read position. </dd>
  <dt><i>size</i></dt>
  <dd>[in] The total size to be sent.</dd>
  <dt><i>block</i></dt>
  <dd>[in] Optional. The size of every data block for file IO.</dd>
</dl>

<h5>Return Value</h5>
<p>On success, <b>sendfile</b> returns the actual size of data that has been sent. Otherwise UDT::ERROR is returned and specific error information can be retrieved by 
<a href="error.htm">getlasterror</a>.</p>

<table width="100%" border="1" cellpadding="1" cellspacing="0" bordercolor="#CCCCCC">
  <tr>
    <td width="17%" class="table_headline"><strong>Error Name</strong></td>
    <td width="17%" class="table_headline"><strong>Error Code</strong></td>
    <td width="83%" class="table_headline"><strong>Comment</strong></td>
  </tr>
  <tr>
    <td>ECONNLOST</td>
    <td>2001</td>
    <td>connection has been broken.</td>
  </tr>
  <tr>
    <td>ENOCONN</td>
    <td>2002</td>
    <td><i>u</i> is not connected.</td>
  </tr>
  <tr>
    <td>EINVOP</td>
    <td>4000</td>
    <td>File or disk system errors.</td>
  </tr>
  <tr>
    <td>EINVSOCK</td>
    <td>5004</td>
    <td><i>u</i> is not an valid socket.</td>
  </tr>
  <tr>
    <td>EDGRAMILL</td>
    <td>5010</td>
    <td>cannot use <i>sendfile</i> in SOCK_DGRAM mode.</td>
  </tr>
  <tr>
    <td>EPEERERR</td>
    <td>7000</td>
    <td>The peer side has an unrecoverable error and this call has to be cancelled. </td>
  </tr>
</table>

<h5>Description</h5>
<p>The <strong>sendfile</strong> method sends certain amount of out of a local file. It is always in blocking mode an neither UDT_SNDSYN nor UDT_SNDTIMEO affects this method. However, the <strong>sendfile</strong> method has a streaming semantics same as <a href="send.htm"><strong>send</strong></a>. </p>
<p>Note that <strong>sendfile</strong> does NOT nessesarily require <strong><a href="recvfile.htm">recvfile</a></strong> at the peer side. Sendfile/recvfile and send/recv are orthogonal 
UDT methods.</p>

<h5>See Also</h5>
<p><strong><a href="send.htm">send</a>, <a href="recv.htm">recv</a>, <a href="recvfile.htm">recvfile</a></strong></p>
<p>&nbsp;</p>

</body>
</html>
